//
//  Settings.m
//  We365
//
//  Created by Pham Khuong Duy on 12/13/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "Settings.h"
#import "Utilities.h"

@implementation Settings

static NSMutableDictionary *allSettings;

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

+ (NSMutableDictionary *)getAllSettings
{
    return allSettings;
}

+ (void)setAllSettings:(NSMutableDictionary *)dict
{
    allSettings = [dict retain];
}

+ (NSString *)settingsFilePath
{
    return [Utilities getFilePath:SettingsName];    
}

+ (void)saveSettings
{
    [allSettings writeToFile:[self settingsFilePath] atomically:YES];    
}

+ (void)loadSettings
{
    if(![self checkExists])    
        [self defaultSettings];    
    else
        allSettings = [[NSMutableDictionary dictionaryWithContentsOfFile:[self settingsFilePath]] copy];
}

+ (void)defaultSettings
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:kKmC, @"1000", nil] forKeys:[NSArray arrayWithObjects:kMeasureKind, kDistance, nil]];
    allSettings = [[NSMutableDictionary dictionaryWithDictionary:dict] copy];       
    [self saveSettings];
}

+ (BOOL)checkExists
{
    return [Utilities checkExists:SettingsName];
}

@end
